package edu.ar.modulo2.valentinis.persist;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionManager {
			
	private static Properties _conf;
	
	static {		
		
		_conf =  new Properties();
		
		try {
			_conf.load(	Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties") );
		} catch (IOException e) {
			System.out.println("ERROR AL CARGAR EL ARCIVO db.preoerties");
			e.printStackTrace();
		}		
	}
	
	public ConnectionManager() {		
	}
	
	public static ConnectionManager getInstance() {
		return new ConnectionManager();
	}
	
	public Connection getConnection() {
		
		Connection con = null;
		
		try {
			Class.forName(_conf.getProperty("driver"));
			con = DriverManager.getConnection( _conf.getProperty("url"), 
											   _conf.getProperty("user"), 
											   _conf.getProperty("pass") );
		} catch (SQLException e) {
			
			System.out.println("ERROR ON CONNECTION OPEN");
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			
			System.out.println("ERROR ON CONNECTION OPEN");
			e.printStackTrace();
		}
		
		return con;		
	}	
}
